<?php
//查看订单文件的员工页面
$document_root = $_SERVER['DOCUMENT_ROOT'];
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Bob`s Auto Parts - Order Results-Bob的汽车配件-订单结果</title>

</head>

<body>
    <h1>Bob`s Auto Parts - Bob的汽车配件</h1>
    <h2>Customer Orders - 客户订单</h2>
<?php

    //Rdad in the entire file - 整个文件中的Rdad
    //Each order becomes an element in the array - 每个顺序都成为数组中的一个元素
    $orders = file("$document_root/orders/orders.txt");

    //count the number of orders in the array - 计算数组中的订单数
    $number_of_orders = count($orders);

    if ($number_of_orders == 0) {
        echo "<p>目前还没有订单</p>";
    };

    echo "<table>\n";
    echo "<tr>
        <th>订单日期</th>
        <th>轮胎</th>
        <th>润滑油</th>
        <th>配件</th>
        <th>合计</th>
        <th>收件地址</th>
    ";

    for ($i=0; $i<$number_of_orders; $i++) {
        //split up each line - 把每一行分开
        $line = explode("\t", $orders[$i] );
        //keep only the number of items ordered - 只保留订购的物品数量
        $line[1] = intval($line[1]);//提取数组中的数组内容 - 几个轮胎
        $line[2] = intval($line[2]);//几瓶润滑油
        $line[3] = intval($line[3]);//几个配件

        //output each order - 每个订单的输出
        echo "<tr>
        <td>".$line[0]."</td>
        <td style=\"text-align: right;\">".$line[1]."</td>
        <td style=\"text-align: right;\">".$line[2]."</td>
        <td style=\"text-align: right;\">".$line[3]."</td>
        <td style=\"text-align: right;\">".$line[4]."</td>
        <td>".$line[5]."</td>
        </tr>
        ";
    }
    echo "</table>";

    

?>

<style>
    table, th, td {
        border-collapse: collapse;
        border: 1px solid black;
        padding: 6px;
    }
    th {
        background: #ccccff;
    }
    </style>
</body>
</html>